﻿<phone:PhoneApplicationPage x:Class="ResumableDownload.View.MainPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.WP7"
                            xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="768"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="Portrait"
                            Orientation="Portrait"
                            shell:SystemTray.IsVisible="True"
                            DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">
    
    <!--LayoutRoot is the root grid where all page content is placed-->
    <controls:Pivot Title="RESUMABLE DOWNLOAD DEMO"
                        Margin="0,0,0,72">
        <controls:PivotItem Header="DL Manager">       
            <Grid x:Name="ContentPanel"
              Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="237" />
                <ColumnDefinition Width="5" />
                <ColumnDefinition Width="80" />
                <ColumnDefinition Width="5" />
                <ColumnDefinition Width="116*" />
                    <ColumnDefinition Width="13*" />
                </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="60" />
                <RowDefinition Height="5" />
                <RowDefinition Height="66" />
                <RowDefinition Height="28" />
                <RowDefinition Height="5" />
                <RowDefinition Height="28" />
                <RowDefinition Height="5" />
                <RowDefinition Height="28" />
                <RowDefinition Height="5" />
                <RowDefinition Height="28" />
                <RowDefinition Height="5" />
                <RowDefinition Height="28" />
                <RowDefinition Height="5" />
                <RowDefinition Height="28" />
                <RowDefinition Height="71" />
                <RowDefinition Height="71" />
                <RowDefinition Height="71" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Button Content="Start"
                    Name="start" Height="71" IsEnabled="{Binding Path=DownloadService.State, Converter={StaticResource StateToStartEnabledConverter}}"
                    Click="StartClicked" Grid.ColumnSpan="3" Margin="0,0,77,0" />
            <Button Content="Stop" Name="stop"
                    Height="71" IsEnabled="{Binding Path=DownloadService.State, Converter={StaticResource StateToStopEnabledConverter}}"
                    Click="StopClicked" Grid.Column="1" Grid.ColumnSpan="5" />
            <Button Content="Delete All"
                    Name="deleteAll" 
                    Height="72" 
                    Grid.Column="1" 
                    Margin="0,0,0,10" Grid.RowSpan="2" cmd:ButtonBaseExtensions.Command="{Binding DeleteAllCommand}" Grid.ColumnSpan="5" Grid.Row="1" />            
            <TextBlock Height="30" Grid.Row="3" Name="status"
                       Text="{Binding Path=DownloadService.State, Converter={StaticResource StateToStatusConverter}}"
                       Margin="12,0,0,0" Grid.ColumnSpan="3" />            
            <Button Content="Download image..."
                    Name="addImage"
                    Grid.Row="14"
                    Grid.RowSpan="2"
                     Grid.ColumnSpan="6"
                    Height="72"
                    VerticalAlignment="Top"
                    cmd:ButtonBaseExtensions.Command="{Binding AddImageCommand}" />
            <Button Content="Download MP3..."
                    Name="addMp3"
                    Grid.Row="15"
                    Grid.RowSpan="2"
                    Grid.ColumnSpan="6"
                    Height="72"
                    VerticalAlignment="Top"
                    cmd:ButtonBaseExtensions.Command="{Binding AddMp3Command}" />
            <Button Content="Download large file..."
                    Name="addLargeFile"
                    Grid.Row="16"
                    Grid.RowSpan="2"
                    Grid.ColumnSpan="6"
                    Height="72"
                    VerticalAlignment="Top"
                    cmd:ButtonBaseExtensions.Command="{Binding AddLargeFileCommand}" />
            <TextBlock
                Name="currentIdentifier"
                Grid.Row="5"
                Grid.ColumnSpan="5"
                Height="30"
                Width="429"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Margin="12,0,0,0"
                Text="{Binding Path=CurrentIdentifier}" />
            <TextBlock
                Name="currentSize"
                Grid.Row="7" Grid.ColumnSpan="5"
                Height="29"
                Width="429"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Margin="12,1,0,0"
                Text="{Binding Path=CurrentRequest, Converter={StaticResource RequestSizeToStringConverter}}" />
            <TextBlock Name="currentDuration"
                Grid.Row="9"
                Grid.ColumnSpan="5"
                Height="30"
                Width="429"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Margin="12,0,0,0"
                Text="{Binding Path=CurrentRequest, Converter={StaticResource RequestDurationToStringConverter}}" />
            <TextBlock Name="currentRemaining"
                Grid.Row="11"
                Grid.ColumnSpan="5" 
                Height="30"
                Width="429"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Margin="12,0,0,0"
                Text="{Binding Path=CurrentRequest, Converter={StaticResource RequestRemainingToStringConverter}}" />
            <TextBlock Name="currentRate"
                       Height="30"
                       Width="226"
                       HorizontalAlignment="Left"
                       Text="{Binding Path=CurrentRequest, Converter={StaticResource RequestSpeedToStringConverter}}"
                       VerticalAlignment="Top"
                       Grid.Row="13"
                       Grid.ColumnSpan="2"
                       Margin="12,0,0,0" />
            <TextBlock Grid.Column="4"
                       Grid.Row="3" Height="30"
                       Width="112"
                       HorizontalAlignment="Left"
                       TextAlignment="Right"
                       Text="{Binding Path=NetworkType}"
                       VerticalAlignment="Top" Margin="2,0,0,0" />
                <TextBlock
                    Grid.Column="2"
                    Grid.ColumnSpan="3"
                    Grid.Row="13" Height="30"
                    Width="199"
                    HorizontalAlignment="Left"
                    TextAlignment="Right"
                    VerticalAlignment="Top"
                    Text="{Binding Path=DownloadService, Converter={StaticResource BlockSizeToStringConverter}}" Margin="0,1,0,0" Grid.RowSpan="2" />
            </Grid>
        </controls:PivotItem>
        <controls:PivotItem Header="All">
            <Grid>
                <Grid.RowDefinitions>                    
                    <RowDefinition Height="415*" />
                </Grid.RowDefinitions>               
                <ListBox Grid.Row="2" BorderThickness="3" BorderBrush="White"
                             Padding="5,5,5,5"
                             ItemsSource="{Binding AllRequests}"
                             ItemTemplate="{StaticResource RequestDataTemplate}"
                             ScrollViewer.VerticalScrollBarVisibility="Visible" />
            </Grid>
        </controls:PivotItem>
        <controls:PivotItem Header="Completed">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="415*" />
                </Grid.RowDefinitions>
                <ListBox Grid.Row="2" BorderThickness="3" BorderBrush="White"
                             Padding="5,5,5,5"
                             ItemsSource="{Binding CompletedRequests}"
                             ItemTemplate="{StaticResource RequestDataTemplate}"
                             ScrollViewer.VerticalScrollBarVisibility="Visible" />
            </Grid>
        </controls:PivotItem>
        <controls:PivotItem Header="Failed">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="415*" />
                </Grid.RowDefinitions>
                <ListBox Grid.Row="2" BorderThickness="3" BorderBrush="White"
                             Padding="5,5,5,5"
                             ItemsSource="{Binding FailedRequests}"
                             ItemTemplate="{StaticResource RequestDataTemplate}"
                             ScrollViewer.VerticalScrollBarVisibility="Visible" />
            </Grid>
        </controls:PivotItem>
        <controls:PivotItem Header="Pending">
            <Grid>
                <ListBox BorderThickness="3" BorderBrush="White"
                             Padding="5,5,5,5"
                             ItemsSource="{Binding PendingRequests}"
                             ItemTemplate="{StaticResource RequestDataTemplate}"
                             ScrollViewer.VerticalScrollBarVisibility="Visible" />
            </Grid>
        </controls:PivotItem>        
    </controls:Pivot>
</phone:PhoneApplicationPage>